﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using Hezi.BLL;
using Hezi.Model;

namespace Hezi.MsgService
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码、svc 和配置文件中的类名“Service1”。
    // 注意: 为了启动 WCF 测试客户端以测试此服务，请在解决方案资源管理器中选择 Service1.svc 或 Service1.svc.cs，然后开始调试。
    public class Msg : IMsg
    {
        /// <summary>
        /// 心跳协议
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public PingModel Ping(string name)
        {
            CacheManager cm = new CacheManager();
            if (cm.ListHas(ConfigKey.msgKeyStart + name))
            {
                return PingModel.HasMsg();
            }
            return PingModel.Default();
        }
        /// <summary>
        /// 检查APP版本
        /// </summary>
        /// <param name="version"></param>
        /// <returns></returns>
        public PingModel CheckVersion(string version)
        {
            if (version != "1.0")
            {
                return new PingModel() { State = 1, Message = "http://hezi.xxxfeng.com/Hezi.App_1_0.apk" };
            }
            return PingModel.Default();
        }
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public int AddUser(string name)
        {
            CacheManager cm = new CacheManager();
            if (cm.HashHasValue(name))
            {
                return 1;
            }
            cm.HashSetNotExpire(name);
            return 0;
        }
        /// <summary>
        /// 获取队列消息
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public MsgModel GetData(string name)
        {
            CacheManager cm = new CacheManager();
            return cm.ListGet<MsgModel>(ConfigKey.msgKeyStart+ name);
        }
    }
}
